package com.carl.controller;

import com.carl.common.ApiResponse;
import com.carl.common.DataListResponse;
import com.carl.common.ReturnMapUtil;
import com.carl.model.DataItem;
import com.carl.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author YuanRL
 * @version 1.0
 * @date 2025/3/17 15:56
 */
@RestController
@RequestMapping("api")
@CrossOrigin("*")
public class ApiController {

    @Autowired
    private ApiService apiService;

    /**
     * 导入数据
     */
    @PostMapping("/uploadFile")
    public ResponseEntity<ApiResponse> uploadFile(MultipartFile excelFile) throws Exception {
        return apiService.uploadFile(excelFile);
    }
    /**
     * 数据列表接口
     */
    @GetMapping("/getDataList")
    public ResponseEntity<DataListResponse> getDataList() {
        try {
            // TODO: 从数据库获取数据
            List<DataItem> dataList = apiService.getDataList();
            return ResponseEntity.ok(new DataListResponse(true, "获取成功", dataList));
        } catch (Exception e) {
            return ResponseEntity.ok(new DataListResponse(false, "获取失败：" + e.getMessage(), null));
        }
    }
}
